package wxk.interview.syn;

public class Test {
    // 类锁：形式1

    public static synchronized void Method1() {
        System.out.println("我是类锁一号");
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    } // 类锁：形式2

    public void Method2() {
        synchronized (Test.class) {
            System.out.println("我是类锁二号");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args){

      MyThread myThread = new MyThread();
      myThread.start();

        Test t = new Test();
        t.Method2();

    }

    static class MyThread extends Thread{
        @Override
        public void run() {
            Test.Method1();
        }
    }
}